// Copyright (c) 2025, 大连理工大学 (Dalian University of Technology)
//
// Licensed under the Mulan PSL v2.
// You can use this file according to the terms and conditions of the Mulan PSL v2.
// You may obtain a copy of the License at
//
//     http://license.coscl.org.cn/MulanPSL2
//
// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
// EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. SEE THE MULAN PSL v2
// FOR MORE DETAILS.

/*
 * @Author: qiulin_JXGM ql1746365080@gmail.com
 * @Date: 2024-09-03 16:49:15
 * @LastEditors: qiulin ql1746365080@gmail.com
 * @LastEditTime: 2024-12-13 19:32:23
 * @FilePath: \SGFEM\Import\NastranBDF\test\Property\PBEAMLParserTest.cpp
 */

#include "Import/BDFImport/BulkData/Property/PBEAMLParser.h"

#include "gtest/gtest.h"

#include "DBManager/DBServiceFactory.h"
#include "DBManager/IService/Input/Property/IPBEAMLService.h"

#include "Import/BDFImport/BDFParserBase.h"
using namespace SG::DBManager;
using namespace SG::Import;
using namespace SG::DataStructure::FEM;
extern std::shared_ptr<DBServiceFactory> DB_SERVICEFACTORY;
extern std::vector<std::string>          dividedEntryInfo;

class PBEAMLParserTest : public ::testing::Test
{
  public:
    static void SetUpTestSuite ()
    {
        DB_SERVICEFACTORY->ClearDatabase ();
    }
};

TEST_F (PBEAMLParserTest, ParseEntry1)
{
    std::vector<std::string> Entry = { "PBEAML        11      21MSCBML0 T                                       +0000022",
                                       "+0000022      6.      8.     2.2     2.6        YES          0.1     6.2+0000023",
                                       "+0000023     8.2     2.4     2.8        YES          0.2     6.4     8.4+0000024",
                                       "+0000024     2.6      3.        YES          0.3     6.6     8.6     2.8+0000025",
                                       "+0000025     3.2        YES          0.4     6.8     8.8      3.     3.4+0000026",
                                       "+0000026        YES          0.5      7.      9.     3.2     3.6        +0000027",
                                       "+0000027YES          0.6     7.2     9.2     3.4     3.8        YES     +0000028",
                                       "+0000028     0.7     7.4     9.4     3.6      4.        YES          0.8+0000029",
                                       "+0000029     7.6     9.6     3.8     4.2        YES          0.9     7.8+000002A",
                                       "+000002A     9.8      4.     4.4        YES     " };
    BDF::divideBulkEntry (Entry, dividedEntryInfo);
    SG::Import::BDF::BULKDATA::ParsePBEAML (DB_SERVICEFACTORY, dividedEntryInfo);

    SG::DataStructure::FEM::PBEAMLData data;
    ASSERT_TRUE (DB_SERVICEFACTORY->get<IPBEAMLService> ()->FindById (11, data) == SG::DataStructure::Common::Status::STATUS_Success);

    ASSERT_TRUE (data.m_section.size () == 11);
    ASSERT_TRUE (data.m_id == 11);
    ASSERT_TRUE (data.m_mId == 21);
}

TEST_F (PBEAMLParserTest, ParseEntry2)
{
    std::vector<std::string> Entry = { "PBEAML         2       2MSCBML0 L                                       +",
                                       "+             3.      6.     2.5      1." };
    BDF::divideBulkEntry (Entry, dividedEntryInfo);
    SG::Import::BDF::BULKDATA::ParsePBEAML (DB_SERVICEFACTORY, dividedEntryInfo);

    SG::DataStructure::FEM::PBEAMLData data;
    ASSERT_TRUE (DB_SERVICEFACTORY->get<IPBEAMLService> ()->FindById (2, data) == SG::DataStructure::Common::Status::STATUS_Success);

    ASSERT_TRUE (data.m_section.size () == 2);
    ASSERT_TRUE (data.m_section[0].m_dims.size () == 4);
    ASSERT_TRUE (data.m_id == 2);
    ASSERT_TRUE (data.m_mId == 2);
}